/**
 * Created by yananliu on 2017/11/11.
 */
export class CookieUtil{
    public static createCookie(name : string,value:string,days:number) {
        if (days) {
            const date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            const expires = "; expires="+date.toUTCString();
        } else {
            const expires = "";
            document.cookie = name+"="+value+expires+"; path=/";
        }
    }
    public static readCookie (name:string) {
        const nameEQ = name + "=";
        const ca = document.cookie.split(';');
        for(let i=0;i < ca.length;i++) {
            let c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    public static eraseCookie (name:string) {
        this.createCookie(name,"",-1);
    }

}